package com.ruoyi.project.poem.incidentalmusic.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.poem.incidentalmusic.domain.IncidentalMusic;
import com.ruoyi.project.poem.incidentalmusic.service.IIncidentalMusicService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 背景音乐Controller
 *
 * @author shixiangwen
 * @date 2022-06-23
 */
@Controller
@RequestMapping("/poem/incidentalmusic")
public class IncidentalMusicController extends BaseController {
    private String prefix = "poem/incidentalmusic";

    @Autowired
    private IIncidentalMusicService incidentalMusicService;

    @RequiresPermissions("poem:incidentalmusic:view")
    @GetMapping()
    public String incidentalmusic() {
        return prefix + "/incidentalmusic";
    }

    /**
     * 查询背景音乐列表
     */
    @RequiresPermissions("poem:incidentalmusic:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IncidentalMusic incidentalMusic) {
        startPage();
        List<IncidentalMusic> list = incidentalMusicService.selectIncidentalMusicList(incidentalMusic);
        return getDataTable(list);
    }

    /**
     * 导出背景音乐列表
     */
    @RequiresPermissions("poem:incidentalmusic:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IncidentalMusic incidentalMusic) {
        List<IncidentalMusic> list = incidentalMusicService.selectIncidentalMusicList(incidentalMusic);
        ExcelUtil<IncidentalMusic> util = new ExcelUtil<IncidentalMusic>(IncidentalMusic.class);
        return util.exportExcel(list, "incidentalmusic");
    }

    /**
     * 新增背景音乐
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存背景音乐
     */
    @RequiresPermissions("poem:incidentalmusic:add")
    @Log(title = "背景音乐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IncidentalMusic incidentalMusic) {
        return toAjax(incidentalMusicService.insertIncidentalMusic(incidentalMusic));
    }

    /**
     * 修改背景音乐
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        IncidentalMusic incidentalMusic = incidentalMusicService.selectIncidentalMusicById(id);
        mmap.put("incidentalMusic", incidentalMusic);
        return prefix + "/edit";
    }

    /**
     * 修改保存背景音乐
     */
    @RequiresPermissions("poem:incidentalmusic:edit")
    @Log(title = "背景音乐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IncidentalMusic incidentalMusic) {
        return toAjax(incidentalMusicService.updateIncidentalMusic(incidentalMusic));
    }

    /**
     * 删除背景音乐
     */
    @RequiresPermissions("poem:incidentalmusic:remove")
    @Log(title = "背景音乐", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(incidentalMusicService.deleteIncidentalMusicByIds(ids));
    }
}
